<template>
  <a-card>
    <div style="width: 100%;height: 40px;">
      <common-search
        v-for="(item,index) in mainQueryObj"
        :key='index'
        :item='item'
        @changeNew='changeNew'
      >
      </common-search>
      <div style='float: right;'>
        <a-button @click="() => {this.queryPage()}" type="primary">查询</a-button>
        <a-button @click="() =>{ queryParam = {}}" style="margin-left: 8px">重置</a-button>
      </div>
    </div>
    <br>
    <div style="width: 100%;">
      <div style="display: flex;justify-content: left;">
        <!--        <a-button @click="addData" icon="plus" type="primary">新建</a-button>-->
        <!--        <a-button @click="addData" icon="download" type="plain" style="margin-left: 12px">下载二维码标签</a-button>-->
      </div>
    </div>
    <v-table
      :toolbar="true"
      bordered
      ref="table"
      :showPagination="false"
      :data="loadData"
      :table-column="tableColumns"
      style="margin-top: 20px;"
    >
      <template v-slot:action="{ text, row }">
         <span>
          <a-popconfirm title="是否处理" @confirm="deleteItem(row)" okText="是" cancelText="否">
            <a-icon slot="icon" type="question-circle-o" style="color: red"/>
            <a href="javascript:;" style="color: red">处理</a>
          </a-popconfirm>
        </span>
        <a-divider type="vertical"/>
        <span @click="details">
          详情
        </span>
      </template>
    </v-table>
    <err-details ref="details"></err-details>
    <!-- 导入 -->
    <b-import-file
      @ok="queryPage"
      :actionUrl="actionUrl"
      ref="BImportFile"/>
  </a-card>
</template>

<script>
  import vTable from "@/components/VxeTableDemo"
  import { pageErrorAlarmList} from '@api/wfuAlarm/wfuAlarm'
  import BImportFile from "@/components/BImportFile";
  import commonSearch from "@/components/commonSearch";
  import errDtails from "./details";

  export default {
    name: "index",
    components: { vTable, BImportFile, commonSearch, errDtails },
    data() {
      return {
        tableColumns:[
          {
            title:'序号',
            field:'index'
          },
          {
            title:'姓名',
            field:'userName'
          },
          {
            title:'学号',
            field:'userCode'
          },
          {
            title:'学院',
            field:'institute'
          },
          {
            title:'专业班级',
            field:'major'
          },
          {
            title:'学生电话',
            field:'mobile'
          },
          {
            title:'导员姓名',
            field:'assistantName'
          },
          {
            title:'导员工号',
            field:'assistantCode'
          },
          {
            title:'导员电话',
            field:'assistantMobile'
          },
          {
            title: '操作',
            width: '100px',
            field: 'action',
            scopedSlots:{customRender:'action'}
          }
        ],
        // 导入接口
        actionUrl: '',
        mainQueryObj: [
          {
            label: '学院',
            value: 'institute',
            code: 'name',
            show:'name',
            type: 'select-multiple',
            rule:'eq',
            val:'',
            options:[  //传入options必须为code，name；组件显示name，回传code
              {code:'0',name:'未提交'},
              {code:'1',name:'审批中'},
              {code:'2',name:'已办结'},
            ]
          },
          {
            label: '班级',
            value: 'major',
            type: 'input',
            rule:'like',
            val:''
          },
          {
            label: '导员',
            value: 'teacher',
            type: 'input',
            rule:'like',
            val:''
          },
          {
            label: '时间',
            value: 'time',
            type: 'date',
            rule:'BETWEEN',
            val:''
          }
        ],
        queryParam: {
        },
        loadData: parameter => {
          return pageErrorAlarmList(
            Object.assign(parameter, this.queryParam)
          ).then(res => {
            return res.data
          })
        }
      }
    },
    methods:{
      // 列接口获取
      initTabColumns() {

      },
      // 删除
      deleteItem (record) {
        /*ParentdelObj(record.id).then(res => {
          if(res.code === 0){
            this.$message.success('删除成功')
            this.queryPage()
          }else{
            this.$message.error(res.message)
          }
        }).catch(err => {
          this.$message.error(err.message)
        })*/
      },
      details() {
        this.$refs.details.show()
      },
      handleSearchOk() {
        this.queryParam.queryItems = encodeURI(JSON.stringify(this.queryArr))
        this.queryPage()
      },
      handleSearchClean() {
        this.queryArr = []
        for( let i = 0; i < this.mainQueryObj.length; i++){
          this.mainQueryObj[i].val = ''
          if( this.mainQueryObj[i].date ){
            this.mainQueryObj[i].date = []
          }
          if( this.mainQueryObj[i].showName ){
            this.mainQueryObj[i].showName = ''
          }
        }
      },
      addData() {},
      queryPage() {
        this.$refs.table.refresh(bool)
      },
      changeNew(e) {
        let isJu = false
        for(let i = 0; i < this.queryArr.length; i++){
          if(e.value == this.queryArr[i].field){
            this.queryArr[i].val = e.val
            isJu = true
            return
          }else{
            isJu = false
          }
        }
        if(isJu == false){
          this.queryArr.push({
            val: e.val,
            field: e.value,
            rule: e.rule
          })
        }
      },
      // 导入
      showModal() {
        this.$refs.BImportFile.show()
      },
      handleExportXls() {
        getCtvEpt().then((response) => {
          let data = response.data
          if (!data) {
            this.$message.warning('文件下载失败')
            return
          }
          let name = decodeURI(response.headers.filename)
          let blob = new Blob([data])
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(blob, name)
          } else {
            let url = window.URL.createObjectURL(blob)
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', name)
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link) //下载完成移除元素
            window.URL.revokeObjectURL(url) //释放掉blob对象
          }
        })
      },

    }
  }
</script>

<style scoped>

</style>